using Godot;
using GoGameClient.script.global;
using GoGameClient.script.map;
using GoGameClient.script.role;

namespace GoGameClient.script.node.world;

public partial class World : Node2D
{
    private ResourcesControl _resourcesControl;
    private TrendsMap _trendsMap;
    private RoleControl _animatedSprite2D;


    public override void _Ready()
    {
        _resourcesControl = ResourcesControl.Instance();
        AddChild( _trendsMap = (TrendsMap)GD.Load<PackedScene>("res://scene/TrendsMap.tscn").Instantiate());
        _animatedSprite2D = GetNode<RoleControl>("RoleControl");
        _animatedSprite2D.OffsetSignal += _trendsMap.DrawMap;
        Init();
    }

    private void Init()
    {
        var roleEntity = UserControl.GetInstance().GetRole();
        _resourcesControl.SetMapResources(roleEntity.MapId);
        _trendsMap.UpdateMapInfo();
        _animatedSprite2D.UpdateCamera2D();
        _animatedSprite2D.SetPosition(new Vector2I(roleEntity.VariantX, roleEntity.VariantX));
        _animatedSprite2D.SetModel(roleEntity.Model);
    }
}